package top.someapp.dxf2dsvg.entity;

import top.someapp.dxf2dsvg.base.Point;
import top.someapp.dxf2dsvg.dxf.Item;
import top.someapp.dxf2dsvg.kits.Numbers;

import javax.annotation.Nonnull;
import java.util.LinkedHashMap;
import java.util.Map;

/**
 * @author zwz
 * Created on 2020-04-20
 */
public class Insert extends EntityBase {
    private boolean start;
    private Map<String, Point> refBlockPointsMap = new LinkedHashMap<>();
    private Point point;

    @Override
    public String type() {
        return "INSERT";
    }

    @Override
    public void setup(@Nonnull Item item) {
//        System.out.println("item in INSERT: " + item);
        if (!start && item.code == 100 && item.value.equals("AcDbBlockReference")) {
            start = true;
            return;
        }
        if (start) {
            switch (item.code) {
                case 2:
                    point = new Point();
                    refBlockPointsMap.put(item.value, point);
                    break;
                case 10:
                    point.setX(Numbers.floatValue(item.value));
                    break;
                case 20:
                    point.setY(Numbers.floatValue(item.value));
                    break;
                case 30:
                    point.setZ(Numbers.floatValue(item.value));
                    break;
            }
        }
    }

    @Override
    public String toString() {
        return "Insert{" +
                "refBlockPointsMap=" + refBlockPointsMap +
                '}';
    }
}
